﻿using System;
using System.Collections.Generic;

using AppKit;
using Foundation;
using SoulCard;

namespace SounCard.Mac
{
    /// <summary>
    /// Data Source - exposes what data goes in each row/column (cell)
    /// </summary>
    public class TableDataSource : NSTableViewDataSource
    {
        #region Private Variables
        readonly List<CardData> mCardDatas;
        #endregion

        #region Constructors
        public TableDataSource(List<CardData> tasks)
        {
            // Initialize
            this.mCardDatas = tasks;
        }
        #endregion

        #region Override Methods
        public override nint GetRowCount(NSTableView tableView)
        {
            // Return the number of tasks
            return mCardDatas.Count;
        }

        public override NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, nint row)
        {
            // Return an empty object if the row is outside of the range
            if (row < 0)
                return new NSObject();

            // Get the current task
            var todo = mCardDatas[(int)row];
            switch (tableColumn.Identifier)
            {
                case "name":
                    return new NSString(todo.Content);
                case "complete":
                    return new NSString(todo.Complete ? "Done" : "Incomplete");
                case "id":
                    return new NSString(todo.Id); // not really a column
            }

            // Return an empty string for an unknown column name
            return new NSString(string.Empty);
        }
        #endregion
    }
}